

package com.zmks.jkgj.xuexiao.controller;




import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.zmks.jkgj.core.controller.ABaseController;
import com.zmks.jkgj.core.resp.Resp;
import com.zmks.jkgj.core.util.IdcardValidator;
import com.zmks.jkgj.xuexiao.SessionManager;
import com.zmks.jkgj.xuexiao.resp.WebResp;
import com.zmks.jkgj.xuexiao.service.ICrctObjTeacherService;

import com.zmks.jkgj.xuexiao.vo.CrctObjClassVO;
import com.zmks.jkgj.xuexiao.vo.CrctObjTeacherVO;
/**
 * 
 * @author jiangyaning
 * 教师操作
 *
 */

@Controller
public class CrctObjTeacherController extends ABaseController {
	@Autowired
	
	private ICrctObjTeacherService crctObjTeacherService;	

	 //查询
	@RequestMapping("/get_CrctObjTeacher_list")
	@ResponseBody
	public Resp get_CrctObjTeacher_list( Integer pageIndex,
			Integer pageSize,HttpServletRequest request) {
        WebResp webResp = new WebResp();
		CrctObjTeacherVO crctObjTeacherVO=new  CrctObjTeacherVO();
		 String  school_oid = SessionManager.getsession(request).getSchool_oid();
		crctObjTeacherVO.setSchool_oid(Long.parseLong(school_oid));
		webResp.setData(crctObjTeacherService.getList(crctObjTeacherVO));
		webResp.setTotalCount(crctObjTeacherService.getCount(crctObjTeacherVO));
			return webResp;
	}
	
	
	 //查询
	@RequestMapping("/get_CrctObjTeacher_one")
	@ResponseBody
	public Resp get_CrctObjTeacher_one( Long oid,HttpServletRequest request) {
        WebResp webResp = new WebResp();
		CrctObjTeacherVO crctObjTeacherVO=new  CrctObjTeacherVO();
		crctObjTeacherVO.setOid(oid);
		webResp.setData(crctObjTeacherService.getUniqueResult(crctObjTeacherVO));
			return webResp;
	}
	 //增加
	@RequestMapping("/save_CrctObjTeacher")
	@ResponseBody
	public Resp save_CrctObjTeacher(String name, 
			String birthday,
			String card_id,
			String email,
			String mobile,
			String sex,
			String subject,
		    String telephone,
		   HttpServletRequest request) {
		WebResp 	webResp = new WebResp();
		try{
		CrctObjTeacherVO crctObjTeacherVO=new  CrctObjTeacherVO();
		crctObjTeacherVO.setName(name);
		//生日
		try{
		SimpleDateFormat sdf =   new SimpleDateFormat("yyyy-MM-dd" );
		
		crctObjTeacherVO.setBirthday(sdf.parse(birthday));
		} catch (Exception e) {
			e.printStackTrace();
			webResp.setRet(1);
			webResp.setErrcode(0);
			webResp.setMsg("日期格式错误！");
			return webResp;
		}
	
			IdcardValidator iv = new IdcardValidator();
			if(!iv.isValidatedAllIdcard(card_id)){
				webResp.setRet(1);
				webResp.setErrcode(0);
				webResp.setMsg("身份证填写错误！");
				return webResp;
			}
			crctObjTeacherVO.setCard_id(card_id);
		

		crctObjTeacherVO.setEmail(email);
		crctObjTeacherVO.setMobile(mobile);
		 String  school_oid = SessionManager.getsession(request).getSchool_oid();
		crctObjTeacherVO.setSchool_oid(Long.parseLong(school_oid));
		crctObjTeacherVO.setSex(sex);
		crctObjTeacherVO.setSubject(subject);
		crctObjTeacherVO.setTelephone(telephone);
		crctObjTeacherVO.setCreate_date(new Date());
		
		crctObjTeacherService.save(crctObjTeacherVO);
		} catch (Exception e) {
			e.printStackTrace();
			webResp.setRet(1);
			webResp.setErrcode(0);
			webResp.setMsg("增加失败！请检查数据格式");
			return webResp;
		}
		return webResp;
	}
	
	
	 //修改
	@RequestMapping("/update_CrctObjTeacher")
	@ResponseBody
	public Resp update_CrctObjTeacher(Long oid ,String name, 
			String birthday,
			String card_id,
			String email,
			String mobile,
			String sex,
			String subject,
		    String telephone,
		   HttpServletRequest request) {
		WebResp 	webResp = new WebResp();
		try{
		CrctObjTeacherVO s_crctObjTeacherVO=new  CrctObjTeacherVO();
		s_crctObjTeacherVO.setOid(oid);
		CrctObjTeacherVO crctObjTeacherVO=crctObjTeacherService.getUniqueResult(s_crctObjTeacherVO);
		
		crctObjTeacherVO.setName(name);
		//生日
		try{
		SimpleDateFormat sdf =   new SimpleDateFormat("yyyy-MM-dd" );
		
		crctObjTeacherVO.setBirthday(sdf.parse(birthday));
		} catch (Exception e) {
			e.printStackTrace();
			webResp.setRet(1);
			webResp.setErrcode(0);
			webResp.setMsg("日期格式错误！");
			return webResp;
		}
	
			IdcardValidator iv = new IdcardValidator();
			if(!iv.isValidatedAllIdcard(card_id)){
				webResp.setRet(1);
				webResp.setErrcode(0);
				webResp.setMsg("身份证填写错误！");
				return webResp;
			}
			crctObjTeacherVO.setCard_id(card_id);
		

		crctObjTeacherVO.setEmail(email);
		crctObjTeacherVO.setMobile(mobile);
		crctObjTeacherVO.setSex(sex);
		crctObjTeacherVO.setSubject(subject);
		crctObjTeacherVO.setTelephone(telephone);
		crctObjTeacherVO.setModify_date(new Date());
		crctObjTeacherService.save(crctObjTeacherVO);
		} catch (Exception e) {
			e.printStackTrace();
			webResp.setRet(1);
			webResp.setErrcode(0);
			webResp.setMsg("修改失败！请检查数据格式");
			return webResp;
		}
		return webResp;
	}
	 //删除
	@RequestMapping("/remove_CrctObjTeacher")
	@ResponseBody
	public Resp remove_CrctObjTeacher(Long id,HttpServletRequest request) {

		WebResp 	webResp = new WebResp();
		CrctObjClassVO crctObjClassVO=new  CrctObjClassVO();
		crctObjTeacherService.remove(id);
		return webResp;
	}
	
	
	

}
